import json
import requests
from typing import Dict, List

url = "http://1733029716806217.cn-wulanchabu.pai-eas.aliyuncs.com/api/predict/server_eas_qwen_7b_chat"
prompt = "hello world"
req = {
    "prompt": prompt,
    "stream": True,
    "temperature": 0.0,
    "top_p": 0.5,
    "top_k": 10,
    "max_tokens": 300,
}
response = requests.post(
    url,
    json=req,
    headers={"Content-Type": "application/json", "Authorization":"ZGE3MTI4NWNjN2UxOTkyYmJiN2ZiNzM5ZGU2YzMyMmQ2OTEwZDBkZQ=="},
    stream=True,
)
for chunk in response.iter_lines(chunk_size=8192, decode_unicode=False):
    msg = chunk.decode("utf-8")
    if msg.startswith('data'):
        info = msg[6:]
        if info == '[DONE]':
            break
        else:
            resp = json.loads(info)
            print(resp['choices'][0]['text'], end='', flush=True)